package com.telecom.cms.dao;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.telecom.cms.dto.PreviewRslt;
import com.telecom.cms.util.Constant;

public class PreviewRsltDAO {
	Dao dao = new DaoImp();

	String db = (new Constant()).getPara("DATABASE");

	public PreviewRsltDAO() {
		super();
	}
	public PreviewRsltDAO(String db) {
		super();
		this.db = db;
	}

	public String getDb() {
		return db;
	}

	public void setDb(String db) {
		this.db = db;
	}

	public List findAll(String tableid,String ordertfield,String ordertype) {

		String sql = "select * from " + db + "  where table_id like '%"+(null==tableid?"":tableid.trim())+"%' order by process_date ";
		if(ordertfield!=null)
			sql+=" order by "+ordertfield+" "+ordertype;
		List list = new ArrayList();
		try {
			ResultSet rs = dao.select(sql);
			while (rs.next()) {
				PreviewRslt sd = new PreviewRslt();
				sd.setSeq_id(rs.getInt(1));
				sd.setProcess_date(rs.getString(2));
				sd.setTable_id(rs.getString(3));
				sd.setPara_value(rs.getString(4));
				sd.setPred_set_cnt(rs.getFloat(5));
				sd.setResult_set_cnt(rs.getFloat(6));
				sd.setPrecision_value(rs.getFloat(7));
				sd.setRecall_value(rs.getFloat(8));
				list.add(sd);
			}
			if (rs != null) {

				rs.close();
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			dao.closeconn();
		}
		return list;

	}
	
	public List findAlltableid() {

		String sql = "select table_id from " + db + "  group by 1";
		List list = new ArrayList();
		try {
			ResultSet rs = dao.select(sql);
			while (rs.next()) {
				list.add(rs.getString(1));
			}
			if (rs != null) {
				rs.close();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			dao.closeconn();
		}
		return list;

	}

}
